﻿using UnityEngine;
using System.Collections;
using Cmd;
using GameData;
using UnityEngine.UI;

public class NewCustomer : MonoBehaviour
{

    public InputField NameField;
    public InputField PhoneField;
    public InputField GetField;
    public InputField CardField;
    public InputField batchField;

    public GameObject sumitBtn;
    public Text label;

	// Use this for initialization
	void Start () {
        EventTriggerListener.Get(sumitBtn).onClick = OnsumitBtn;

    }

    // Update is called once per frame
    void Update () {
	
	}

    void OnsumitBtn(GameObject obj)
    {
        label.text = "";
        if (string.IsNullOrEmpty(NameField.text))
        {
            label.text = "输入姓名";
            return;
        }
        if (string.IsNullOrEmpty(GetField.text))
        {
            label.text = "输入收据";
            return;
        }
        if (string.IsNullOrEmpty(CardField.text))
        {
            label.text = "输入身份证";
            return;
        }
        if (string.IsNullOrEmpty(batchField.text))
        {
            label.text = "输入批次";
            return;
        }
        if (!GlobalVO.GetInstance().NumAllInfo.batchList.Contains(batchField.text))
        {
            label.text = "!检查批次";
            return;
        }
        if (CardField.text.Length!=6)
        {
            label.text = "身份证需要后6位";
            return;
        }
        //
        NewCustomerInfo nc = new NewCustomerInfo();
        CustomerData cd = new CustomerData();
        cd.name = NameField.text;
        cd.MoneyNumLists.Add(GetField.text);
        cd.IdCard = CardField.text;
        cd.phone = PhoneField.text;
        cd.@group = batchField.text;
        nc.Send(cd, newResponse);

    }

    public void newResponse(NumberData nd)
    {
        if (nd.value==1)
        {
            label.text = "成功";
        }
        else
        {
            label.text = "检查批次!";
        }
        NameField.text = "";
        GetField.text = "";
        CardField.text = "";
        PhoneField.text = "";
        batchField.text = "";
    }

}
